import React from "react";
class CommentForm extends React.Component{
    state = {
        name:'',
        comment:''
    }
    handlerForm = () =>{
        this.props.getForm(this.state)
        this.handlerReset()
    }
    handlerChange = (e) => {
        const value = e.target.value
        const name = e.target.name
        this.setState({
            [name]:value
        })
    }
    handlerReset = () =>{
        console.log('-----')
        this.setState({
            name:'',
            comment:''
        })
    }
    render(){
        return (
            <div>
                <div>
                    <input type='text' value={this.state.name} name="name" placeholder="请输入评论人" onChange={this.handlerChange}></input>
                </div>
                <div>
                    <textarea value={this.state.comment} cols={30} rows={3} name="comment" placeholder="请输入评论内容" onChange={this.handlerChange}></textarea>
                </div>
                <div>
                    <button onClick={this.handlerForm}>提交</button>
                </div>
            </div>
        )
    }
}
export default CommentForm